import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

import com.mysql.jdbc.PreparedStatement;

public class DBDemo
{
  // The JDBC Connector Class.
	

  // Connection string. emotherearth is the database the program
  // is connecting to. You can include user and password after this
  // by adding (say) ?user=paulr&password=paulr. Not recommended!


   DBDemo()
  {
	   try {
	Class.forName("com.mysql.jdbc.Driver");
	Connection con = DriverManager.getConnection("jdbc:mysql://localhost/testdb","root","need2bezair");
	PreparedStatement statement = (PreparedStatement) con.prepareStatement("select * from names");
	
	ResultSet result = statement.executeQuery();
	
	while(result.next())
	{
		System.out.println(result.getString(1) + " " + result.getString(2));
	}



    }
	   catch(Exception ex) {
		   
	   }
	   finally {
		   // Your must-always-be-executed code goes between these 
		   // curly braces. Like closing database connection.
		   System.out.print("Exception");
		}
  }
}